package jmu.cze.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class CustomerInterceptor implements HandlerInterceptor {
    // 在拦截点执行前拦截
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();

        if(session.getAttribute("id")!=null && (Integer) session.getAttribute("permission") == 0) {
            return true;
        } else {
            response.sendRedirect(request.getContextPath()+"/info");
            return false;
        }
    }
}
